package com.huazi.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huazi.educms.entity.CrmBanner;
import com.huazi.educms.mapper.CrmBannerMapper;
import com.huazi.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author huazi
 * @since 2021-03-25
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Override
    public boolean addBannerAdmin(CrmBanner banner) {
        int insert = baseMapper.insert(banner);
        return insert > 0 ? true : false;
    }

    @Override
    public boolean modBannerAdmin(CrmBanner banner) {
        int insert = baseMapper.update(banner,null);
        return insert > 0 ? true : false;
    }

    @Override
    public boolean deleteBannerAdmin(String id) {
        int insert = baseMapper.deleteById(id);
        return insert > 0 ? true : false;
    }

    @Override
    public List<CrmBanner> getBannerAdmins() {
        return baseMapper.selectList(null);
    }

    @Override
    public CrmBanner getBannerAdminOne(String id) {
        return baseMapper.selectById(id);
    }
    //查询banner信息
    @Cacheable(key = "'selectIndexList'",value = "banner")
    @Override
    public List<CrmBanner> getBannerFroms() {
        //需要降序排列，并只要前两条记录
        List<CrmBanner> list = baseMapper.selectList(
                null
//                new QueryWrapper<CrmBanner>()
//                        .orderByDesc("id")
//                        .last("limit 2")
        );//last拼接sql语句
        return list;
    }
}
